
function initImp(dialogId,url){
    $(document).dialog({id:dialogId,width:500,height:400,
        url:url,
        data:'',
        title:'导入数据',mask:true,
        onClose:function(json){

        }
    });
}

function batchState(url,datagrid,state) {
    var ids=getSelectedDataIds(datagrid);
    if(ids==""){
        BJUI.alertmsg('info', "请选择");
        return ;
    }
    changeState(ids,url,datagrid,state);
}



function changeState(ids,url,datagrid,state) {
    $.ajax({
        type: "POST",
        url:url,
        data:{id:ids,state:state},
        success: function (data) {
            if(data.statusCode == '200'){
                if(data.message!=""){
                    BJUI.alertmsg('info', data.message);
                }
                $("#"+datagrid).datagrid("refresh",true);
            }else{
                BJUI.alertmsg('warn', data.message);
            }
        }
    });
}



function getSelectedDataIds(datagrid){
    var ids="";
    var $selectTrs = $("#"+datagrid).find("tr.datagrid-selected-tr");
    if($selectTrs.length==0){
        return ids;
    }
    var selectedDatas = $("#"+datagrid).data('selectedDatas');
    if(typeof(selectedDatas) == "undefined"){
        return "";
    }
    for(var i = 0; i < selectedDatas.length; i++){
        ids = ids+selectedDatas[i].id+",";
    }
    return ids;
}




function select_country(selectId,defaultValue){
    $.ajax({
        type:"GET",
        url:"/select/country",
        success:function(data){
            var html="<option value='' >----全部----</option>";
            for(var i=0;i<data.length;i++){
                if(defaultValue
                    &&defaultValue==data[i].value){
                    html=html
                        +"<option " +
                        "value='"+data[i].value+"' selected>"+data[i].label+"</option>";
                }else{
                    html=html+"<option value='"+data[i].value+"' >"+data[i].label+"</option>";
                }
            }
            $("#"+selectId).html(html).selectpicker('refresh');
        }
    });
}


function select_option(selectId,className,defaultValue,exclude){
    $.ajax({
        type:"GET",
        url:"/select",
        data:{"className":className,"exclude":exclude?exclude:""},
        success:function(data){
            var html="<option value='' >----全部----</option>";
            for(var i=0;i<data.length;i++){
                if(defaultValue
                    &&defaultValue==data[i].code){
                    html=html
                        +"<option " +
                        "value='"+data[i].code+"' selected>"+data[i].display+"</option>";
                }else{
                    html=html+"<option value='"+data[i].code+"' >"+data[i].display+"</option>";
                }
            }
            $("#"+selectId).html(html).selectpicker('refresh');
        }
    });
}


function createRandomId() {
    return "a"+(Math.random()*10000000).toString(16).substr(0,4)+'-'
        +(new Date()).getTime()+'-'+Math.random().toString().substr(2,5);
}

function openDialog(width,height,title,url,data){
    var id=createRandomId();
    BJUI.dialog({
        id:id,
        url:url,
        width: width,
        height: height,
        data:data,
        type:'POST',
        title:title,
        mask:true
    })
}

function resetAll(){
    try{
        $('select').selectpicker('val',"");
        $('select').selectpicker('refresh');
        $('input').iCheck('uncheck');
    }catch (e) {
        alert(e);
    }

}




